import os
from google.appengine.ext.webapp import template

from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.ext import db

import re,sys,datetime
import datastore
import library

from google.appengine.api import users

class GetMembers(webapp.RequestHandler):
    def Write(self,t):
      self.response.out.write(t)

    def get(self):

       self.response.headers['Content-Type'] = 'text/html'

       fac =  self.request.get('facility') 
       if( fac==""):   fac = "lp"


       facilityid,facilityname= library.getfacilityNameID( fac )
       query="select __key__ from FacilityRoster where facility=" + facilityid + " order by lname,fname "


       self.Write( query + "<br>")
       self.Write( facilityname + ' Members<br>')

       last=""
       keys = db.GqlQuery( query )
       for k in keys:
          t = db.get(k)
          if(last!=t.fname+t.lname):
           self.Write( t.fname + ", " + t.lname + "<br>")

          last=t.fname+t.lname
   

application = webapp.WSGIApplication(
                                     [('/members', GetMembers)],
                                     debug=True)

def main():
    run_wsgi_app(application)

if __name__ == "__main__":



#   print __file__
#   print __name__


    main()
